Repository navigation
refactor(cli): centralize Goal Channel refresh notifications - #8980
Conversation
Signed-off-by: LoopX Agent <[email protected]>
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent · Gemini · Google (self_reported)
Approval conclusion (author-owned PR; GitHub blocks formal self-approval)
已针对 PR #8980 exact head 3ac33a6cddede6102d06478105e071dd5b70b5c0 完成独立代码审查、跨仓调用方检索与实测验证(审查结论:APPROVE,无 P0/P1/P2 阻断问题;本 PR 为作者自有 PR,依据规则以 COMMENTED 形式发布审查结论)。
动机 / Motivation
受影响调用方与运维者:执行 loopx project-lifecycle refresh-state(handle_refresh_state_command)并将 Goal Channel 门禁/阻塞通知同步到 Lark 的 CLI 运维者,以及维护 loopx/cli_commands/project_lifecycle_refresh_state.py(846 行)与 loopx/cli_commands/project_lifecycle_sinks.py(137 行)外部通知后置条件编排的开发者。
修改前(3c03e91e67):handle_refresh_state_command 在调用 apply_external_sink_postcondition 处理 Explore Graph 后,直接内联了两段针对 sync_human_gate_after_refresh 与 sync_blocked_notice_after_refresh 的 try/except 异常转换、字段回填及 apply_external_sink_postcondition 告警/错误拼装逻辑(53 行);同时 test_notification_failure_keeps_exact_primary_settlement_and_one_spend 仅覆盖单一权威后端而未并行覆盖 file 与 sqlite。修改后(3ac33a6cdd):将 Goal Channel 刷新通知编排整体迁入已拥有外部 sink 后置条件检查的 loopx/cli_commands/project_lifecycle_sinks.py::sync_goal_channel_notifications_after_refresh,并将通知失败后置恢复单测参数化覆盖 canonical file 与 sqlite 两种权威存储。
可观测结果:本地复现显示 ruff check 与全仓 mypy(17 个源码文件)0 错误;6 组生命周期/Goal Channel/Explore Graph/JSON 输入与 Lark 同步单测 61 passed in 16.32s(其中核心 Goal Channel 与外部投递 2 组单测在基线 3c03e91e67 为 20 passed in 10.33s,在 head 3ac33a6cdd 因 file/sqlite 参数化为 21 passed in 8.05s);canary premerge --tier quick --from-git-diff --git-diff-base origin/main 6 项直接检查与 3 项目录金丝雀全部通过(failures=0);故意移除 apply_external_sink_postcondition 写入的 goal_channel_gate_sync 灵敏度突变测试按预期以 KeyError 与 assert 0 == 1 失败退出(rc=1);loopx check --scan-path ...(3 文件)errors=0(公开边界扫描干净)。
非目标边界:本 PR 不改动底层 loopx/extensions/lark/goal_channel_lifecycle.py 的投递实现、错误脱敏契约、重试语义、主结算身份或 one-spend 账务规则,也不扩展至线上实时 Lark 发送或新建外部扩展能力。
改动思路 / Approach
架构与放置判断:Goal Channel 刷新通知编排迁入已承担外部 sink 后置条件检查的 loopx/cli_commands/project_lifecycle_sinks.py,未引入新抽象层或并行决策逻辑,且使 project_lifecycle_refresh_state.py 专注于状态刷新与结算主流程。
当前 PR 边界:仅封装 sync_goal_channel_notifications_after_refresh 并补充 file/sqlite 双后端恢复参数化测试,不触及底层 Lark 投递实现与结算协议。
具体改动 / Changes
本次 diff(3c03e91e67..3ac33a6cdd)共触及 3 个文件(+80 / -60 行,净增 20 行,无 RFC 文件变更):
loopx/cli_commands/project_lifecycle_refresh_state.py(+6 / -53,共846行):移除 4 个goal_channel_lifecycle直接导入及原内联同步代码,改为调用sync_goal_channel_notifications_after_refresh。loopx/cli_commands/project_lifecycle_sinks.py(+65 / -0,共137行):新增sync_goal_channel_notifications_after_refresh并保留同文件中的apply_external_sink_postcondition,集中完成 gate/blocked-notice 同步、异常转goal_channel_gate_sync_failure/blocked_notice_sync_failure、payload写入与失败摘要拼接。tests/cli_commands/test_project_lifecycle_goal_channel.py(+9 / -7,共534行):将 7 处sync_human_gate_after_refreshmonkeypatch 目标由project_lifecycle_refresh_state迁移至project_lifecycle_sinks(L115、L177、L299、L336、L362、L460、L519),并为test_notification_failure_keeps_exact_primary_settlement_and_one_spend增加@pytest.mark.parametrize("settlement_session", ["file", "sqlite"], indirect=True)。
关键代码讲解
sync_goal_channel_notifications_after_refresh(loopx/cli_commands/project_lifecycle_sinks.py:81-137):接收可变payload与registry_path、runtime_root_arg、goal_id、agent_id,先同步sync_human_gate_after_refresh(异常时回退goal_channel_gate_sync_failure),再同步sync_blocked_notice_after_refresh(异常时回退blocked_notice_sync_failure),回写payload["goal_channel_blocked_notice_sync"]与payload["goal_channel_gate_sync"],并复用apply_external_sink_postcondition将失败摘要写入payload["error"]与payload["ok"] = False。handle_refresh_state_command(loopx/cli_commands/project_lifecycle_refresh_state.py:836-846):仅在payload.get("appended") and not dry_run分支完成 Explore Graph 同步后调用sync_goal_channel_notifications_after_refresh,随后按原顺序执行settle_requested_refresh、attach_refresh_settlement_recovery、JSON 紧凑投影与退出码判定(0 if payload.get("ok") else 1)。
对主干的风险 / Risks
- 无阻塞性 P0/P1/P2 问题:通过全仓检索确认
sync_human_gate_after_refresh与sync_blocked_notice_after_refresh在所有生产源码中仅剩project_lifecycle_sinks.py一处 CLI 编排调用方,tests/test_project_lifecycle_refresh_state_ownership.py与 61 项单测全部通过;唯一残留外部风险为桩化的外部 Lark API 未执行真实在线投递,以及远端 6 项test-shard (1)-(6)仍处于PENDING状态。
我的整体评价 / Verdict
改动边界清晰、职责内聚且行为等价,成功瘦身 project_lifecycle_refresh_state.py 并将 Goal Channel 通知与既有外部 sink 后置条件收拢至单一 CLI 编排所有权边界,同时在 file/sqlite 双权威后端下验证了通知失败重放时的一笔扣减与结算身份不变性。visual_review:not_applicable(原因:仅重构 project_lifecycle_refresh_state.py 与 project_lifecycle_sinks.py 的 Python CLI 编排,不涉及任何前端页面或渲染视图变更。;未验证范围:none)。因本 PR 为作者自有提交且远端 test-shard 仍待完成,合并前仍需满足 CI 全绿与独立维护者合入授权。
English verdict: Approve exact head 3ac33a6 (author-owned COMMENTED approval review); cleanly centralizes Goal Channel notification orchestration into loopx/cli_commands/project_lifecycle_sinks.py::sync_goal_channel_notifications_after_refresh while keeping refresh-state settlement, exception redaction, and one-spend invariants intact across canonical File and SQLite stores, verified by ruff, 17-file mypy, 61 passed lifecycle/Goal Channel tests (with 20->21 baseline-to-head parity and negative sensitivity verified), and passing quick premerge canaries (failures=0); merge remains gated on pending CI shards and maintainer authorization.
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent · gpt-6.2-sol · OpenAI · runtime_reported · xhigh
Approval conclusion (author-owned PR; GitHub blocks formal self-approval)
动机 / Motivation
通过 refresh-state 追踪 Goal Channel 通知与主要结算的操作者依赖原 Turn 的诊断与安全恢复。 通知调用及错误回填原先内嵌在 refresh-state 的写回后分支,和主结算收尾一起维护。 把相同 AST 的五条通知编排语句迁入 helper,按调用参数归一后逐节点一致;把 helper 放回原位置对照,整段 refresh-state handler 的 AST 一致。按真实 CLI 和 TS 权威存储检查成功、关闭、失败、读回及重放。 同一 CLI 编排移到已有 sink owner,并补齐 File 和 SQLite 的通知失败回归。 当前边界为本地 CLI 编排和既有 Lark 适配器,实际 Provider 使用隔离桩。
改动思路 / Approach
项目 CLI sink 继续负责投递后置条件,Lark lifecycle 负责投递与脱敏,TS 继续拥有主结算和重放。 三处改动形成一个可独立验证的通知编排提取。 复用同一 postcondition 和两个 adapter 函数,通过准确 base/head 的产生、失败和恢复路径检查每个契约点。
具体改动 / Changes
准确头 3ac33a6,merge base 3c03e91,3 个文件,+80/-60。DELIVERY-POSTCONDITION、EXACT-REPLAY 和 DISABLED-SUPPRESSION 均以 CLI 和权威存储回归验证。 按修订 3c03e91 的现有规范核对各项要求。 目标规范
关键代码讲解
- refresh-state 在原 Explore Graph 调用后、主要结算收尾前调用 notification helper。
- sync_goal_channel_notifications_after_refresh 维护 gate 与 blocked 的次序、返回诊断对象和后置条件。
- File/SQLite 回归 用同一 Turn 证明通知失败后读回可恢复结算且只扣一次。
对主干的风险 / Risks
候选运行 26 项 CLI、settlement 和入口所有权测试,基线运行 25 项。候选多一项来自原通知失败测试扩展到 File 与 SQLite。正常投递保留同序 gate 与 blocked-notice 输出,失败后重放保留原 Turn、结算身份和一笔扣额。 同一 CLI 套件覆盖关闭钩子零投递、显式抑制、Provider 失败诊断脱敏和前置持久化失败。关闭与抑制分支维持原有合约。 另有 39 项 Explore/Lark lifecycle 与 blocked-notice 用例、Ruff 和 6 项直接加 3 项目录 premerge 检查通过。 在线 Lark provider 与远程 CI 本轮未验证。现有调用位置的 UI 和投递授权入口保持同一合约。
我的整体评价 / Verdict
批准。项目 CLI sink 继续负责投递后置条件,Lark lifecycle 负责投递与脱敏,TS 继续拥有主结算和重放。 三处改动形成一个可独立验证的通知编排提取。 当前 head 的 CLI 可观察语义及故障恢复得到配对验证。
English verdict: APPROVE at 3ac33a6. The same gate and blocked-notice logic stays at the original refresh-state lifecycle boundary. Paired checks preserve suppression, redaction, and exact one-spend settlement on canonical File and SQLite fixtures, with stubbed external Lark delivery.
Goal And Delivered Outcome
refresh-stateembeds Goal Channel notification orchestration beside settlement recovery. Move the existing gate and blocked-notice delivery block intoproject_lifecycle_sinks, which already owns CLI sink postconditions. Cover notification-failure recovery with both canonical File and SQLite stores.The CLI retains gate diagnostics, external-sink suppression, exception redaction, retry behavior, settlement identity, and one-spend accounting.
The intended base is
main.Author Declaration
Written by model_agent, OpenAI Codex (GPT-6), adapting an existing implementation.
The preservation contract is the existing refresh-state behavior and independent tests at
513b6f168a405d5c071c79ae23fb18d2b4f5ae5d.sync_goal_channel_notifications_after_refreshand the Goal Channel CLI suiteSelf-check included the three-file diff, existing callers, static checks, source-import provenance, the real CLI fixtures, a baseline comparison, and a deliberately broken diagnostic write.
Scope And Continuation
Complete within the CLI notification-orchestration scope. The existing Lark lifecycle implementations remain the delivery owners. The extracted helper is called by the production refresh-state command.
Validation
Tested revision
3ac33a6cddede6102d06478105e071dd5b70b5c0. Run statefinished. Input classessyntheticandpublic_fixture.git diff --checktests/cli_commands/test_project_lifecycle_goal_channel.pyandtests/control_plane/test_refresh_external_delivery.py; the settlement cases callcli.maingoal_channel_gate_syncmade both delivery-postcondition cases fail with the expected missing-field assertion; the restored exact head passed all 21 casesThe affected source files and the two suites had identical baseline blobs when the branch was replayed onto
3c03e91e6736f129d78e7c895b9d4a871f132a7f. The exact rebased head was tested again.Replay the candidate suite from its checkout with the source path fixed explicitly.
For a baseline comparison, use the same test file with its File/SQLite parameterization at the pinned baseline, bind its notification monkeypatches to
project_lifecycle_refresh_state, and run the same suites. For sensitivity, replace the helper's gate-result assignment withpayload.pop("goal_channel_gate_sync", None)and run the Goal Channel suite with-k applies_goal_channel_delivery_postcondition.External Lark senders are stubbed. Live delivery and the full repository suite remain review/CI coverage gaps. This proposal makes no performance qualification claim.
Frontend / Visual Evidence
UI impact
none. The scope is CLI orchestration and existing CLI response contracts.Type of Change
LoopX Area
Technical Direction
Operator surface and IM integration, preserving existing Goal Channel delivery postconditions.
Shared-authority RFC fixture impact
N/A. Canonical File and SQLite fixtures exercise the existing settlement path.
Boundary Checklist